﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Xml;

namespace LicPdaService
{
    public class MainHandler
    {
        public static string lsReturn = "";
        public static string MessageHandler(string xml, string type)
        {
            XmlDocument doc = new XmlDocument();//实例化参数xml报文
            doc.LoadXml(xml);
            App.DBconSet(); //数据库连接设定 

            //===========================================
            try
            {
                //登录
                if (type == "登录")
                {
                    lsReturn = LicPdaService.Login.GetUser(xml);
                }
            }
            catch (Exception ex)
            {
                App.Log("登录", ex.ToString());
                throw;
            }

            //===========================================
            try
            {
                if (type == "原料到货验收")
                {
                    lsReturn = LicPdaService.PDAXmlCheckProcess.GetCheck(xml);

                }
            }
            catch (Exception ex)
            {
                App.Log("1.0原料到货验收", ex.ToString());
                throw;
            }

            //===========================================
            try
            {
                if (type == "原料上架库位库存")
                {
                    lsReturn = LicPdaService.PDAXmlPutawayProcess.GetPutaway(xml);
                }
            }
            catch (Exception ex)
            {
                App.Log("2.0原料上架库位库存", ex.ToString());
                throw;
            }

            //===========================================
            try
            {
                if (type == "原料上架分配")
                {
                    lsReturn = LicPdaService.PDAXmlPutPackProcess.GetPutPack(xml);
                }
            }
            catch (Exception ex)
            {
                App.Log("2.1原料上架分配", ex.ToString());
                throw;
            }

            //===========================================
            try
            {
                if (type == "空箱扫描库存")
                {
                    lsReturn = LicPdaService.PDAXmlPrePickProcess.GetPDAPrePickData(doc);
                }
            }
            catch (Exception ex)
            {
                App.Log("3.0空箱扫描库存", ex.ToString());
                throw;
            }

            //===========================================
            try
            {
                if (type == "空箱扫描叫料")
                {
                    lsReturn = LicPdaService.PDAXmlOrderPickProcess.GetPDAOrderPickData(doc);
                }
            }
            catch (Exception ex)
            {
                App.Log("3.1空箱扫描叫料", ex.ToString());
                throw;
            }

            //===========================================
            try
            {
                if (type == "拣货库存")
                {
                    lsReturn = LicPdaService.PDAXmlPickIntoryProcess.GetPickIntory(doc);
                }

            }
            catch (Exception ex)
            {
                App.Log("4.0拣货库存", ex.ToString());
            }

            //===========================================
            try
            {
                if (type == "拣货确认")
                {
                    lsReturn = LicPdaService.PDAXmlPickUpdeProcess.GetPickUpde(doc);
                }

            }
            catch (Exception ex)
            {
                App.Log("4.1拣货确认", ex.ToString());
            }

            //===========================================
            try
            {
                if (type == "料号有效性")
                {
                    lsReturn = LicPdaService.PDAXmlSkuCheckProcess.GetSkuCheckData(doc);
                }

            }
            catch (Exception ex)
            {
                App.Log("9.0料号有效性", ex.ToString());
            }


            //10.0通过出货信息扫描生成托盘号--调拨通用方法
            //===========================================
            try
            {
                if (type == "调拨通用方法")
                {
                    string type_temp = string.Empty;
                    DataTable ldt = LicPdaService.App.Xml2DataTable(xml);
                    if (ldt.Rows.Count == 0)
                    {
                        return "";

                    }

                    if (ldt.Rows.Count != 0)
                    {
                        type_temp = ldt.Rows[0]["MessageType"].ToString();
                    }

                    if (type_temp == "PickUp")
                    {
                        lsReturn = LicPdaService.PickUp.OrdGetPickUp(xml); //拣货查询
                    }
                    else if (type_temp == "PickUpTray")//生成托盘号
                    {
                        lsReturn = LicPdaService.PickUp.OrdTray(xml);
                    }
                    else if (type_temp == "PickUpPrint")//打印托盘号
                    {
                        lsReturn = LicPdaService.PickUp.OrderPickTrayPrint(xml);
                    }
                    //10.2通过出库单号、托盘号、打印托盘标签
                    // lsReturn = LicPdaService.PickUp.OrderPickTrayPrint(xml);

                }

            }
            catch (Exception ex)
            {
                App.Log("10.0调拨入库通用方法、托盘号、打印托盘标签", ex.ToString());
            }

                  //===========================================
                  try
                  {
                        if (type == "扫描提取信息")
                        {
                          //   lsReturn = LicPdaService.PDAXmlCheckProcess.GetCheck(xml);
                              lsReturn = LicPdaService.PDAXmlGetScanInformation.GetScanInformation(xml);

                        }
                  }
                  catch (Exception ex)
                  {
                        App.Log("11.0扫描提取信息", ex.ToString());
                        throw;
                  }

                  return lsReturn;
        }
    }
}
